var app = getApp();
var that;
var utils = require('js/utils.js');
Page({
  data: {
    name:'',
    signDesc:'',
    college:'',
    time:'',
    student:'',
    price:'',
    subjectTags:'',
    skillTags:'',
    albumImages:'',
    point:'',
    talkList:'',
    isLove:false,
    showModalStatus:false,
    loveModalStatus:false,
    loveText:"您好，是关注吗？"
  },
  onShow:function(){
      that = this; 
      console.log(app.teacherDetailData);
      that.setData(
        {
          icon:app.teacherDetailData.avatar,
          name:app.teacherDetailData.name,
          isLove: app.chooseListItem.isDefault == 1?true:false,
          follow:app.teacherDetailData.follow,
          signDesc:app.teacherDetailData.autograph,
          college:app.teacherDetailData.school,
          time:utils.formatDateTimeOne(app.teacherDetailData.createtime),
          student:app.teacherDetailData.doing,
          price:app.teacherDetailData.cost,
          subjectTags:app.teacherDetailData.subjects,
          skillTags:app.teacherDetailData.ability,
          point:app.teacherDetailData.score
        }
      );
      that.setData({
            albumImages:app.teacherDetailData.album
        }
      );
      try{
            that.setData({
                    talkList:utils.changeDate(app.teacherDetailData.pingjia)
                    }
            );
      }catch(e){

      }
  },
  love:function(){
      that.setData(
        {
            loveText:"您要取消关注吗?",
            loveModalStatus:true
        });
  },
  unlove:function(){
      that.setData(
            {
                loveText:"您要关注吗?",
                loveModalStatus:true
            }
        );
  },
  modalBindaconfirm:function(){
        utils.loveClick(app.openId,app.teacherId,function(isOk,data){
            if(isOk){
              app.chooseListItem.detailRevise = true;
              if (that.data.isLove){//ai
                  app.chooseListItem.isDefault = 0;
                }else{//bu ai
                  app.chooseListItem.isDefault = 1;
                }
                that.setData({
                    loveModalStatus:false,
                    isLove:!that.data.isLove
                });
            }else{
                wx.showToast({
                    title: '加载失败',
                    icon: 'cancel',
                    mask:true,
                    duration: 2000
                });
            }
        });
    },
    modalBindcancel:function(){
        that.setData({loveModalStatus:false});
    },
    onShareAppMessage: function (res) {
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
      title: '欢迎使用教带',
      path: 'pages/splash/splash',
      success: function(res) {
        // 转发成功
      },
      fail: function(res) {
        // 转发失败
      }
    }
  }
})